﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Text;
using Xamarin.Forms;

namespace AppBlank.ViewModels
{
    public class VideoListViewPageViewModel : BaseViewModel
    {
        Services.IDataServices Services = new Services.ListViewDemoService();

        public ObservableCollection<Models.KuaiYinShiVideo> kuaiYinShiVideos { get; set; }

        public ObservableCollection<View> views { get; set; }
        public int CurrentIndex=0;
        int page = 1;
        public VideoListViewPageViewModel()
        {
            Title = "App One";
            kuaiYinShiVideos = new ObservableCollection<Models.KuaiYinShiVideo>();
            views = new ObservableCollection<View>();
            var list = Services.GetVideoList(page);
            if (list != null)
            {
                foreach (var item in list)
                {
                    views.Add(new Pages.VideoView( item));
                    kuaiYinShiVideos.Add(item);
                }

            }



            MessagingCenter.Subscribe<Pages.VideoListViewPage>(this, "LoadVideo", (obj) =>
            {
                //  meiZiTuFuLi.AddRange(Services.GetMeiZiTuFuLi());
                page += 1;
                list = Services.GetVideoList(page);
                if (list != null)//可能返回null
                {
                    foreach (var item in list)
                    {
                        views.Add(new Pages.VideoView(item));
                        kuaiYinShiVideos.Add(item);
                    }

                }
            });
        }


    }
}
